#include <stdio.h>
int Change;
char* reverse_str(const char* str){
	int len=strlen(str);
	len=len+Change;
	char* ret=(char*)malloc(len+1);
	//reverse read str
	int lastpos=len-1;
	int retpos=0;
	for(;len>0;len--){
		if(str[len-1]==' '){
			//find a word copy len-1,lastpos to start of ret
			int tmp=len;
			for(;tmp<=lastpos;tmp++){
				ret[retpos++]=str[tmp];
			}
			ret[retpos++]=' ';
			lastpos=len-2;
		}
	}
	if(lastpos>0){
		//last word
		int tmp=0;
		for(;tmp<lastpos;tmp++){
			ret[retpos++]=str[tmp];
		}
	}
	return ret;
}


int main(){
	int len=strlen("hello");
	Change=len-5;
	
	char* str="hello note this william";
	
	printf("%s\n",reverse_str(str));
	return 0;
}